package com.fyzk.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fyzk.activity.app.App;
import com.fyzk.activity.prize.item.PrizeItemBase;
import com.fyzk.activity.prize.item.PrizeItemFactory;
import com.fyzk.bean.PrizeHistoryItem;
import com.tyjc.lottery.R;
import com.fyzk.utils.L;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.utils.ScreenUtils;


public class PrizeHistoryLotteryItemView extends RelativeLayout {
	
	private final  String TAG = this.getClass().getSimpleName();

	private Context mContext;
	private TextView mTxt_peroid;
	private TextView mTxt_date;
	private LinearLayout mLl_num;

	public PrizeHistoryLotteryItemView(Context context) {
		this(context, null);
	}

	public PrizeHistoryLotteryItemView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public PrizeHistoryLotteryItemView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		View.inflate(mContext, R.layout.layout_prizehistory_item, this);
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		this.setBackgroundColor(Color.WHITE);
		mTxt_peroid = (TextView) findViewById(R.id.prizehistory_txt_peroid);
		mTxt_date = (TextView) findViewById(R.id.prizehistory_txt_date);
		mLl_num = (LinearLayout) findViewById(R.id.prizehistory_txt_number);
	}

	public void setPeroid(String peroid) {
		mTxt_peroid.setText(mContext.getString(R.string.text_di_qi, peroid));
	}

	public void setDate(String date) {
		mTxt_date.setText(date);
	}

	public void setPrizeHistoryItem(PrizeHistoryItem item, int index) {
		PrizeItemBase itemBase = PrizeItemFactory.getInstance().getPrizeItem(
				item);
		if (index == 0) {
			L.v("setPrizeHistoryItem", "prizeNum" + itemBase.getPrizeNum());
			itemBase.initNumView(mLl_num);
		} else {
			float density = ScreenUtils.getInstance().getDensity();
			TextView mTxt_ball = new TextView(App.getContext());
			LayoutParams layoutParams = new LayoutParams(
					LayoutParams.MATCH_PARENT, (int) (30 * density));
			mTxt_ball.setLayoutParams(layoutParams);
			mTxt_ball.setGravity(Gravity.CENTER_VERTICAL);
			mTxt_ball.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
			mTxt_ball.setText(itemBase.formatPrizeNumSpanned());
			mLl_num.removeAllViews();
			mLl_num.addView(mTxt_ball);
		}
		// itemBase.formatPrizeNumSpanned();
		setPeroid(item.phase);
		
		L.v(TAG, "item.lotteryNum>>>>"+item.wincode);
		L.v(TAG, "item.lotteryDate>>>>"+item.drawTime);
		
		setDate(item.drawTime);
	}

	public void setPrizeNum() {

		//
		// TextView txt = new TextView(mContext);
		// txt.setTextSize(AppUtil.dip2px(mContext, 16));
		// PrizeSelectBallsRulesUtil numColorRules = new
		// PrizeSelectBallsRulesUtil(
		// lottery_num, lotteryID);
		// Spanned num = numColorRules.encodeLotteryNum(
		// numColorRules.getPrizeSelectBallsNum(),
		// numColorRules.getPrizeSelectBallsRule());
		// txt.setValue(num);
	}

	// public void setPrizeNum(String lottery_num, String lotteryID,int
	// position) {
	// if(lottery_num == null || lottery_num.equals("")){
	// return;
	// }
	// if(position != 0){
	// TextView txt = new TextView(mContext);
	// txt.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
	// PrizeSelectBallsRulesUtil numColorRules = new PrizeSelectBallsRulesUtil(
	// lottery_num, lotteryID);
	// Spanned num = numColorRules.encodeLotteryNum(
	// numColorRules.getPrizeSelectBallsNum(),
	// numColorRules.getPrizeSelectBallsRule());
	// txt.setValue(num);
	// mLl_num.addView(txt);
	// }else{
	// PrizeQueryBallPopHelper.initBallNumLinearLayout(mLl_num, mContext,
	// lotteryID, lottery_num);
	// }
	// }
	public void setSumCode(String sumcode, String lotteryID) {
		TextView txt = new TextView(mContext);
		txt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
		txt.setPadding(20, 0, 0, 0);
		txt.setTextColor(getResources().getColor(R.color.tc_default));
		txt.setText("和值:" + sumcode);
		if (lotteryID
				.equals(String.valueOf(LotteryIDUtils.NXK3_LOTTERY_ID_INT))) {
			mLl_num.addView(txt);
		}
	}

}
